﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="WindowWrapper.cs" company="http://buginbox.wordpress.com/">
//   Copyright (c) GNU General Public License version 2 (GPLv2)
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Windows;

namespace Wpf.Core.Behavior
{
    /// <summary>
    /// Defines a wrapper for the <see cref="Window"/> class that implements the <see cref="IWindow"/> interface.
    /// </summary>
    public class WindowWrapper : IWindow
    {
        /// <summary>
        /// The _window.
        /// </summary>
        private readonly Window _window;

        /// <summary>
        /// Initializes a new instance of the <see cref="WindowWrapper"/> class. Initializes a new instance of <see cref="WindowWrapper"/> .
        /// </summary>
        public WindowWrapper()
        {
            _window = new Window();
        }

        /// <summary>
        /// Ocurrs when the <see cref="Window"/> is closed.
        /// </summary>
        public event EventHandler Closed
        {
            add
            {
                _window.Closed += value;
            }

            remove
            {
                _window.Closed -= value;
            }
        }

        /// <summary>
        /// Occurs when the <see cref="IWindow"/> is closing.
        /// </summary>
        public event CancelEventHandler Closing
        {
            add
            {
                _window.Closing += value;
            }

            remove
            {
                _window.Closing -= value;
            }
        }

        /// <summary>
        /// Gets or sets the content for the <see cref="Window"/> .
        /// </summary>
        public object Content
        {
            get
            {
                return _window.Content;
            }

            set
            {
                _window.Content = value;
            }
        }

        /// <summary>
        /// Gets or sets the <see cref="Window.Owner"/> control of the <see cref="Window"/> .
        /// </summary>
        public object Owner
        {
            get
            {
                return _window.Owner;
            }

            set
            {
                _window.Owner = value as Window;
            }
        }

        /// <summary>
        /// Gets or sets the <see cref="FrameworkElement.Style"/> to apply to the <see cref="Window"/> .
        /// </summary>
        public Style Style
        {
            get
            {
                return _window.Style;
            }

            set
            {
                _window.Style = value;
            }
        }

        /// <summary>
        /// Opens the <see cref="Window"/> .
        /// </summary>
        public void Show()
        {
            _window.ShowDialog();
        }

        /// <summary>
        /// Closes the <see cref="Window"/> .
        /// </summary>
        public void Close()
        {
            _window.Close();
        }
    }
}